package com.kun.controller.foreign;


import com.kun.entity.BlogType;
import com.kun.result.Result;
import com.kun.service.impl.BlogTypeServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SunKun
 * @since 2021-06-14
 */
@RestController
@Slf4j //日志
@CrossOrigin  //允许跨域
@RequestMapping("kun/foreign/blogType")
public class BlogTypeController {
    @Autowired
    private BlogTypeServiceImpl blogTypeService;

    /**
     * 查询博客类型和数量
     * @return
     */
    @GetMapping("/queryBlogTypeAndCount")
    @ResponseBody
    public Result queryBlogTypeAndCount(){
        Map<String,Object> map = new HashMap<>();
        try {
            List<BlogType> blogTypes = blogTypeService.queryBlogTypeAndBlogCount();
            return Result.ok().data("blogTypes",blogTypes);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error();
        }
    }
}

